<template>
  <div class="my-new-finance">
    <v-dialog title="复核新增调整复核" :show.sync="dialogVisible" width="1200px" @beforeClose="beforeClose" :close-on-click-modal="false">
      <div class="card-box">
        <div class="card-title">基本信息</div>
        <el-form ref="editForm" :model="form" class="form-wrap" size="small" label-position="top">
          <el-form-item label="关联合同" prop="propertyNames">
            <span>{{form.propertyNames}}</span>
          </el-form-item>
          <el-form-item label="收款项目" prop="chargeProjectName">
            <span>{{form.chargeProjectName}}</span>
          </el-form-item>
          <el-form-item label="出租方" prop="customerName" v-if="customerNameShow">
            <span>{{form.customerName}}</span>
          </el-form-item>
          <el-form-item label="合同应收金额" prop="receivableMoney">
            <span>{{form.receivableMoney}}</span>
          </el-form-item>
          <el-form-item label="费用周期" prop="costPeriodArr">
            <span>{{form.costPeriodStart}}至{{form.costPeriodEnd}}</span>
          </el-form-item>
          <el-form-item label="应收日期" prop="adjustmentDate">
            <span>{{form.adjustmentDate}}</span>
          </el-form-item>
          <el-form-item label="备注" class="full" prop="remarks">
            <span>{{form.remarks}}</span>
          </el-form-item>
        </el-form>
        <div class="card-title">查看附件</div>
        <div class="handling-opinions">
          <v-upload ref="collectionUpload" :busId="projectId" modelType="finance" isShowFileList :isView="true" multiple v-model="fileList" />
        </div>
        <div class="card-title">操作记录</div>
        <div class="handling-opinions">
          <approval-record v-for="(item,index) in recordingLlist" :key="index" v-bind="item"></approval-record>
        </div>
        <div class="card-title">办理意见</div>
        <div class="handling-opinions">
          <el-input type="textarea" v-model="opinion" maxlength="100" placeholder="请输入" class="full"></el-input>
        </div>
      </div>
      <span slot="foot">
        <el-button @click="handleCancel">取 消</el-button>
        <el-button v-throttle=" [commit]">复核不通过并退回</el-button>
        <el-button v-throttle=" [commitReview]">复核通过</el-button>
      </span>
    </v-dialog>
  </div>
</template>

<script>
import { getApprovalRecord, getAdjustment, ApproveByAdjustment, getCollection, changeAdjustment } from '../../api/collection'
import BaseLoad from '@/assets/vue-mixin/BaseLoad'
export default {
  name: "review-payable",
  mixins: [BaseLoad],
  data () {
    return {
      dialogVisible: false,
      customerNameShow: true,
      fileList: [],
      recordingLlist: [],
      projectId: '',
      opinion: '',
      form: {
        chargeProjectName: '',
        propertyNames: '',
        costProjectName: '',
        payableMoney: '',
        costPeriodStart: '',
        costPeriodEnd: '',
        payableDate: '',
        remarks: '',
        opinion: '',
        payableStatus: '',
        adjustmentId: ''
      }
    }
  },
  methods: {
    //打开弹框
		async show (item) {
			this.loadAction('数据加载中，请稍等...')
      if (item) {
        this.projectId = item.adjustmentId
				await getAdjustment(item.adjustmentId).then(res => {
          if (res.data.code === 0) {
            this.form = res.data.data
          }
        })
				await getCollection(item.receivableId).then(res => {
          if (res.data.code === 0) {
            this.form.customerName = res.data.data.customerName
            this.customerNameShow = false
            this.$nextTick(() => {
              this.customerNameShow = true
            })
          }
        })
				this.dialogVisible = true
				this.loadClose()
        this.approvalRecord(item.adjustmentId)
      }
    },
    //关闭弹框
    beforeClose (done) {
    	done()
      this.$emit('beforeClose')
    },
    //请求操作记录
    async approvalRecord (id) {
      const res = await getApprovalRecord(id)
      if (res.data.code == 0) {
        this.recordingLlist = res.data.data
      }
    },
    //取消
    handleCancel () {
      this.dialogVisible = false
			this.$emit('handleCancel')
    },
    //保存
    commit () {
      if (this.opinion === '' || this.opinion === null || this.opinion === undefined) {
        this.$message.error('办理意见不能为空！')
      } else {
        this.data = {
          opinion: this.opinion,
          adjustmentId: this.form.adjustmentId,
          status: '2'
        }
        this.sendFormData(this.data)
      }
    },
    //保存并提交复核
    commitReview () {
      changeAdjustment(this.projectId).then(res => {
        if (res.data.code === 0) {
          this.data = {
            opinion: this.opinion ? this.opinion : '复核通过',
            adjustmentId: this.form.adjustmentId,
            status: '1'
          }
          this.sendFormData(this.data)
        } else {
          this.err(res.data.msg)
        }
      })
    },
    //提交
    sendFormData (val) {
      this.loadAction('请稍等...')
      ApproveByAdjustment(val).then(resp => {
        if (resp.data.data) {
          this.suc('操作成功')
          this.dialogVisible = false
          this.loadClose()
          this.$emit('resetList')
        } else {
          this.err('操作失败')
          this.loadClose()
        }
      })
    },
  }
}
</script>

<style scoped lang="scss">
@include formWrap(4);
.handling-opinions {
  padding: 20px;
  /deep/.el-textarea__inner {
    border: 0.5px solid #ccc;
  }
}
</style>
